/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.hydms.students.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.google.common.collect.Lists;
import com.thinkgem.jeesite.common.beanvalidator.BeanValidators;
import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.utils.DateUtils;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.common.utils.excel.ExportExcel;
import com.thinkgem.jeesite.common.utils.excel.ImportExcel;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.hydms.dormitory.entity.DmsDormitory;
import com.thinkgem.jeesite.modules.hydms.dormitory.service.DmsDormitoryService;
import com.thinkgem.jeesite.modules.hydms.students.entity.DmsStudents;
import com.thinkgem.jeesite.modules.hydms.students.service.DmsStudentsService;

/**
 * 学生信息Controller
 * @author 孟朋朋
 * @version 2017-04-01
 */
@Controller
@RequestMapping(value = "${adminPath}/students/dmsStudents")
public class DmsStudentsController extends BaseController {

	@Autowired
	private DmsStudentsService dmsStudentsService;
	@Autowired
	private DmsDormitoryService dmsDormitoryService;
	
	@ModelAttribute
	public DmsStudents get(@RequestParam(required=false) String id) {
		DmsStudents entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = dmsStudentsService.get(id);
		}
		if (entity == null){
			entity = new DmsStudents();
		}
		return entity;
	}
	@RequiresPermissions("students:dmsStudents:edit")
	@RequestMapping(value = "adjustmentAll")
	public String adjustmentAll(DmsStudents dmsStudents,DmsDormitory dmsDormitory,String idstrs,  Model model, RedirectAttributes redirectAttributes) {
		System.err.println("学生id:"+idstrs);
		String temp1[] = idstrs.split(":");
		System.out.println("数组："+temp1.length);
		/*本方学生id*/
		String str1=temp1[0];
		System.out.println("str1:"+str1);
		String temp2[] = str1.split(",");
		/*对方学生id*/
		String str2=temp1[1];
		System.out.println("str2:"+str2);
		String temp3[] = str2.split(",");
		/*本方宿舍号*/
		String dmsDormitoryNum1=null;
		/*对方宿舍号*/
		String dmsDormitoryNum2=null;
		/*房间空床位*/
		String oRoomBed=null;
		/*房间id*/
		String oDormitoryId=null;
		/***1.获得本方宿舍号****/
		for(String stId:temp2){
			System.out.println("学生id:"+stId);
			 dmsStudents=dmsStudentsService.get(stId);
		    dmsDormitoryNum1=dmsStudents.getDormitoryNumber();
		    dmsDormitory.setDormitoryNumber(dmsDormitoryNum1);
		    List<DmsDormitory> dList=dmsDormitoryService.findList(dmsDormitory);
			   for(DmsDormitory dor:dList){
				   oRoomBed=dor.getRoomBed();
				   oDormitoryId=dor.getId();
			   }
			int roomBed1=Integer.parseInt(oRoomBed)+1;
		   
				String roomBed2=String.valueOf(roomBed1);
				System.out.println("本方宿舍号房间1:"+roomBed2);
				dmsDormitory.setRoomBed(roomBed2);
				dmsDormitory.setId(oDormitoryId);
				dmsStudents.setId(stId);
				dmsStudents.setDormitoryNumber("");
				dmsStudentsService.updateDormitory(dmsStudents);
				dmsStudentsService.updateRoomBed(dmsDormitory);	
		}
		System.out.println("本方宿舍号1:"+dmsDormitoryNum1);
		/***2.获得对方宿舍号****/
		for(String stId:temp3){
			System.out.println("学生id:"+stId);
			dmsStudents=dmsStudentsService.get(stId);
		    dmsDormitoryNum2=dmsStudents.getDormitoryNumber();
		    dmsDormitory.setDormitoryNumber(dmsDormitoryNum2);
		    List<DmsDormitory> dList=dmsDormitoryService.findList(dmsDormitory);
			   for(DmsDormitory dor:dList){
				   oRoomBed=dor.getRoomBed();
				   oDormitoryId=dor.getId();
			   }
			int roomBed1=Integer.parseInt(oRoomBed)+1;
		   
				String roomBed2=String.valueOf(roomBed1);
				System.out.println("本方宿舍号房间2:"+roomBed2);
				dmsDormitory.setRoomBed(roomBed2);
				dmsDormitory.setId(oDormitoryId);
				dmsStudents.setId(stId);
				dmsStudents.setDormitoryNumber("");
				dmsStudentsService.updateDormitory(dmsStudents);
				dmsStudentsService.updateRoomBed(dmsDormitory);	
		}
		System.out.println("本方宿舍号2:"+dmsDormitoryNum2);
		/***3.同时更新双方宿舍信息***/
		for(String stId:temp2){
			System.out.println("学生id:"+stId);
			 dmsStudents=dmsStudentsService.get(stId);
		  /*  dmsDormitoryNum1=dmsStudents.getDormitoryNumber();*/
		    dmsDormitory.setDormitoryNumber(dmsDormitoryNum1);
		    List<DmsDormitory> dList=dmsDormitoryService.findList(dmsDormitory);
			   for(DmsDormitory dor:dList){
				   oRoomBed=dor.getRoomBed();
				   oDormitoryId=dor.getId();
			   }
			int roomBed1=Integer.parseInt(oRoomBed)-1;
		   
				String roomBed2=String.valueOf(roomBed1);
				System.out.println("本方宿舍号房间3:"+roomBed2);
				dmsDormitory.setRoomBed(roomBed2);
				dmsDormitory.setId(oDormitoryId);
				dmsStudents.setId(stId);
				dmsStudents.setDormitoryNumber(dmsDormitoryNum2);
				dmsStudentsService.updateDormitory(dmsStudents);
				dmsStudentsService.updateRoomBed(dmsDormitory);	
		}
		for(String stId:temp3){
			System.out.println("学生id:"+stId);
		   dmsStudents=dmsStudentsService.get(stId);
		   /* dmsDormitoryNum2=dmsStudents.getDormitoryNumber();*/
		    dmsDormitory.setDormitoryNumber(dmsDormitoryNum2);
		    List<DmsDormitory> dList=dmsDormitoryService.findList(dmsDormitory);
			   for(DmsDormitory dor:dList){
				   oRoomBed=dor.getRoomBed();
				   oDormitoryId=dor.getId();
			   }
			int roomBed1=Integer.parseInt(oRoomBed)-1;
		   
				String roomBed2=String.valueOf(roomBed1);
				System.out.println("本方宿舍号房间4:"+roomBed2);
				dmsDormitory.setRoomBed(roomBed2);
				dmsDormitory.setId(oDormitoryId);
				dmsStudents.setId(stId);
				dmsStudents.setDormitoryNumber(dmsDormitoryNum1);
				dmsStudentsService.updateDormitory(dmsStudents);
				dmsStudentsService.updateRoomBed(dmsDormitory);	
		}
		
		addMessage(redirectAttributes, "保存学生信息成功");
		return "redirect:"+Global.getAdminPath()+"/students/dmsStudents/adjustmentList?repage";
		
	}
	
	
	/**
	 * 
	 * adjustmentoOtherSide:(房间对调另一个)
	 * 
	 * @param idstr
	 * @param dmsStudents
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequiresPermissions("dormitory:dmsDormitory:view")
	@RequestMapping(value = "adjustmentoOtherSide")
	public String adjustmentoOtherSide(String idstr,DmsStudents dmsStudents,HttpServletRequest request, HttpServletResponse response, Model model) {
		System.out.println("学生："+idstr);
		Page<DmsStudents> page = dmsStudentsService.findPage(new Page<DmsStudents>(request, response), dmsStudents); 
		model.addAttribute("page", page);
		model.addAttribute("idstr",idstr);
		return "hydms/students/adjustmentoOtherSide";
	}
	/**
	 * 
	 * updateAdjustment:(调整到可以入住的房间)
	 * 
	 * @param dmsStudents
	 * @param dmsDormitory
	 * @param stuId
	 * @param dormitoryId
	 * @param model
	 * @param redirectAttributes
	 * @return
	 */
	@RequiresPermissions("students:dmsStudents:edit")
	@RequestMapping(value = "updateAdjustment")
	public String updateAdjustment(DmsStudents dmsStudents,DmsDormitory dmsDormitory,String stuId,String dormitoryId,  Model model, RedirectAttributes redirectAttributes) {
		System.err.println("学生id:"+stuId);
		System.err.println("宿舍id:"+dormitoryId);
		dmsDormitory.setId(dormitoryId);
	  
	   String oldDnumber= dmsStudentsService.get(stuId).getDormitoryNumber();
	   String oRoomBed=null;
	   String oDormitoryId=null;
	   DmsDormitory dmsDormitory1=new DmsDormitory();
	   dmsDormitory1.setDormitoryNumber(oldDnumber);
	   List<DmsDormitory> dList=dmsDormitoryService.findList(dmsDormitory1);
	   for(DmsDormitory dor:dList){
		   oRoomBed=   dor.getRoomBed();
		   oDormitoryId=dor.getId();
	   }
	   int roomBed3=Integer.parseInt(oRoomBed)+1;
	   System.out.println("老房间入住前："+roomBed3);
	   String roomBed4=String.valueOf(roomBed3);
	   System.out.println("老房间入住后："+roomBed4);
		dmsDormitory1.setRoomBed(roomBed4);
		dmsDormitory1.setId(oDormitoryId);
		dmsStudentsService.updateRoomBed(dmsDormitory1);
		dmsStudents.setId(stuId);
		dmsStudents.setDormitoryNumber(dmsDormitoryService.get(dmsDormitory).getDormitoryNumber());
		System.out.println("宿舍号："+dmsDormitoryService.get(dmsDormitory).getDormitoryNumber());
		int roomBed1=Integer.parseInt(dmsDormitoryService.get(dmsDormitory).getRoomBed());
		if(roomBed1>=1){
		 roomBed1=Integer.parseInt(dmsDormitoryService.get(dmsDormitory).getRoomBed())-1	;
		String roomBed2=String.valueOf(roomBed1);
		dmsDormitory.setRoomBed(roomBed2);
		dmsStudentsService.updateDormitory(dmsStudents);
		dmsStudentsService.updateRoomBed(dmsDormitory);
		
		addMessage(redirectAttributes, "保存学生信息成功");
		return "redirect:"+Global.getAdminPath()+"/students/dmsStudents/adjustmentList?repage";}
		else{
			addMessage(redirectAttributes, "房间已住满！");
			return "redirect:"+Global.getAdminPath()+"/students/dmsStudents/adjustments?repage";
			
			
		}
		
	}
	
	
	
	/**
	 * 
	 * adjustments:(房间单个调整页面)
	 * 
	 * @param stuId
	 * @param dmsDormitory
	 * @param dmsStudents
	 * @param request
	 * @param response
	 * @param redirectAttributes
	 * @param model
	 * @return
	 */
	@RequiresPermissions("dormitory:dmsDormitory:view")
	@RequestMapping(value = "adjustments")
	public String adjustments(String stuId,DmsDormitory dmsDormitory,DmsStudents dmsStudents,HttpServletRequest request, HttpServletResponse response,RedirectAttributes redirectAttributes, Model model) {
		System.out.println("学生："+stuId);

	    String dormitoryNumber= dmsStudentsService.get(stuId).getDormitoryNumber();
	    System.out.println("宿舍号："+dormitoryNumber);
		
		Page<DmsDormitory> page = dmsDormitoryService.findPage(new Page<DmsDormitory>(request, response), dmsDormitory); 
		model.addAttribute("page", page);
		model.addAttribute("dmsDormitory", dmsDormitory);
		model.addAttribute("stuId",stuId);
		return "hydms/students/dmsStudentsAdjustments";
		
	}
	/**
	 * 
	 * adjustmentList:(房间调整List)
	 * 
	 * @param dmsStudents：学生信息实体类 
	 * @param request：
	 * @param response
	 * @param model
	 * @return
	 */
	@RequiresPermissions("students:dmsStudents:view")
	@RequestMapping(value = "adjustmentList")
	public String adjustmentList(DmsStudents dmsStudents, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<DmsStudents> page = dmsStudentsService.findPage(new Page<DmsStudents>(request, response), dmsStudents); 
		model.addAttribute("page", page);
		return "hydms/students/dmsStudentsAdjustmentList";
	}
	/**
	 * 
	 * updateAllStatus:(更新多个人员房间信息)
	 * 
	 * @param dmsStudents
	 * @param dmsDormitory
	 * @param idstr
	 * @param dormitoryId
	 * @param model
	 * @param redirectAttributes
	 * @return
	 */
	@RequiresPermissions("students:dmsStudents:edit")
	@RequestMapping(value = "updateAllStatus")
	public String updateAllStatus(DmsStudents dmsStudents,DmsDormitory dmsDormitory,String idstr,String dormitoryId,  Model model, RedirectAttributes redirectAttributes) {
		System.out.println("学生String:"+idstr);
		System.out.println("宿舍id:"+dormitoryId);
		String temp1[] = idstr.split(",");
		System.out.println("数组："+temp1.length);
		dmsDormitory.setId(dormitoryId);
		int roomBed1=Integer.parseInt(dmsDormitoryService.get(dmsDormitory).getRoomBed());
		if(roomBed1>=temp1.length){
			
		     for(String  num:temp1){
		    	 
				System.out.println("学号："+num);
				dmsStudents.setId(num);
				dmsStudents.setDormitoryNumber(dmsDormitoryService.get(dmsDormitory).getDormitoryNumber());
			    roomBed1=Integer.parseInt(dmsDormitoryService.get(dmsDormitory).getRoomBed())-1	;
		
			    String roomBed2=String.valueOf(roomBed1);
			
				dmsDormitory.setRoomBed(roomBed2);
				dmsStudentsService.updateDormitory(dmsStudents);
				dmsStudentsService.updateRoomBed(dmsDormitory);
			}
			
			addMessage(redirectAttributes, "保存学生信息成功");
			return "redirect:"+Global.getAdminPath()+"/students/dmsStudents/list?repage";
			}
			else{
				model.addAttribute("idstr",idstr);
				addMessage(redirectAttributes, "房间已住满！");
			return "redirect:"+Global.getAdminPath()+"/students/dmsStudents/distributions?idstr="+idstr+"&repage";}
			
			
		}
			
	
	/****
	 * 
	 * distributions:(多个人的房间分配)
	 * 
	 * @param stuId
	 * @param dmsDormitory
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequiresPermissions("dormitory:dmsDormitory:view")
	@RequestMapping(value = "distributions")
	public String distributions(String idstr,DmsDormitory dmsDormitory,HttpServletRequest request, HttpServletResponse response, Model model) {
		System.out.println("学生："+idstr);
		Page<DmsDormitory> page = dmsDormitoryService.findPage(new Page<DmsDormitory>(request, response), dmsDormitory); 
		model.addAttribute("page", page);
		model.addAttribute("dmsDormitory", dmsDormitory);
		model.addAttribute("idstr",idstr);
		return "hydms/students/dmsStudentDistributions";
	}
	
	/**
	 * 
	 * updateStatus:(单个人分配更新)
	 * 
	 * @param dmsStudents
	 * @param dmsDormitory
	 * @param stuId
	 * @param dormitoryId
	 * @param model
	 * @param redirectAttributes
	 * @return
	 */
	@RequiresPermissions("students:dmsStudents:edit")
	@RequestMapping(value = "updateStatus")
	public String updateStatus(DmsStudents dmsStudents,DmsDormitory dmsDormitory,String stuId,String dormitoryId,  Model model, RedirectAttributes redirectAttributes) {
		System.err.println("学生id:"+stuId);
		System.err.println("宿舍id:"+dormitoryId);
		dmsDormitory.setId(dormitoryId);
	    dmsStudents.setId(stuId);;
		dmsStudents.setDormitoryNumber(dmsDormitoryService.get(dmsDormitory).getDormitoryNumber());
		int roomBed1=Integer.parseInt(dmsDormitoryService.get(dmsDormitory).getRoomBed());
		if(roomBed1>=1){
		 roomBed1=Integer.parseInt(dmsDormitoryService.get(dmsDormitory).getRoomBed())-1	;
		String roomBed2=String.valueOf(roomBed1);
		dmsDormitory.setRoomBed(roomBed2);
		dmsStudentsService.updateDormitory(dmsStudents);
		dmsStudentsService.updateRoomBed(dmsDormitory);
		
		addMessage(redirectAttributes, "保存学生信息成功");
		return "redirect:"+Global.getAdminPath()+"/students/dmsStudents/list?repage";}
		else{
			addMessage(redirectAttributes, "房间已住满！");
			return "redirect:"+Global.getAdminPath()+"/students/dmsStudents/distribution?repage";
			
			
		}
		
	}
	
	/**
	 * 
	 * distribution:(单个人房间分配)
	 * 
	 * @param dmsStudents
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequiresPermissions("dormitory:dmsDormitory:view")
	@RequestMapping(value = "distribution")
	public String distribution(String stuId,DmsDormitory dmsDormitory,DmsStudents dmsStudents,HttpServletRequest request, HttpServletResponse response,RedirectAttributes redirectAttributes, Model model) {
		System.out.println("学生："+stuId);
		
	   String dormitoryNumber= dmsStudentsService.get(stuId).getDormitoryNumber();
	   System.out.println("宿舍号："+dormitoryNumber);
		if("".equals(dormitoryNumber)){
		Page<DmsDormitory> page = dmsDormitoryService.findPage(new Page<DmsDormitory>(request, response), dmsDormitory); 
		model.addAttribute("page", page);
		model.addAttribute("dmsDormitory", dmsDormitory);
		model.addAttribute("stuId",stuId);
		return "hydms/students/dmsStudentsDistribution";
		}else{
			
			addMessage(redirectAttributes, "该学生已分配！");
			return "redirect:"+Global.getAdminPath()+"/students/dmsStudents/list?repage";
		}
	}
	
	/**
	 * 
	 * checkStudentNumber:(验证学号)
	 * 
	 * @param dmsStudents
	 * @param request
	 * @param response
	 * @param model
	 */
	@RequiresPermissions("students:dmsStudents:view")
	@RequestMapping(value = "checkStudentNumber")
	public void checkStudentNumber(DmsStudents dmsStudents, HttpServletRequest request, HttpServletResponse response, Model model) {
	String studentNumber=request.getParameter("studentNumber");
	dmsStudents.setStudentNumber(studentNumber);
	try {
		if(dmsStudentsService.findList(dmsStudents).size()<1){
			response.getWriter().print("true");
	      }else{
			response.getWriter().print("false");
	          }
	     } catch (IOException e) {
		e.printStackTrace();
	    }
	  }
	
	/**
	 * 导出用户数据
	 * @param user
	 * @param request
	 * @param response
	 * @param redirectAttributes
	 * @return
	 */
	@RequiresPermissions("students:dmsStudents:view")
    @RequestMapping(value = "export", method=RequestMethod.POST)
    public String exportFile(DmsStudents student, HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes) {
		try {
            String fileName = "学生数据"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
            Page<DmsStudents> page = dmsStudentsService.findPage(new Page<DmsStudents>(request, response, -1), student);
            /*new ExportExcel("学生数据", DmsStudents.class).setDataList(page.getList()).writeFile( fileName).dispose();*/
    		new ExportExcel("学生数据", DmsStudents.class).setDataList(page.getList()).write(response, fileName).dispose();
    		return null;
		} catch (Exception e) {
			addMessage(redirectAttributes, "导出学生失败！失败信息："+e.getMessage());
		}
		return "redirect:"+Global.getAdminPath()+"/students/dmsStudents/list?repage";
    }
	/**
	 * 导入用户数据
	 * @param file
	 * @param redirectAttributes
	 * @return
	 */
	@RequiresPermissions("students:dmsStudents:edit")
    @RequestMapping(value = "import", method=RequestMethod.POST)
    public String importFile(MultipartFile file, RedirectAttributes redirectAttributes) {
		if(Global.isDemoMode()){
			addMessage(redirectAttributes, "演示模式，不允许操作！");
			return "redirect:"+Global.getAdminPath()+"/students/dmsStudents/list?repage";
		}
		try {
			int successNum = 0;
			int failureNum = 0;
			StringBuilder failureMsg = new StringBuilder();
			ImportExcel ei = new ImportExcel(file, 1, 0);
			List<DmsStudents> list = ei.getDataList(DmsStudents.class);
		
			for (DmsStudents student : list){
				try{
					if ("".equals(student.getStudentNumber())&&(dmsStudentsService.findAList(student).size()<1)){
						System.out.println(dmsStudentsService.findList(student).size());
						BeanValidators.validateWithException(validator, student);
						dmsStudentsService.save(student);
						successNum++;
					}else{
						failureMsg.append("<br/>学号 "+student.getStudentNumber()+"<br/>姓名"+student.getStudentName()+" 已存在; ");
						failureNum++;
					}
				}catch(ConstraintViolationException ex){
					failureMsg.append("<br/>学号 "+student.getStudentNumber()+"<br/>姓名"+student.getStudentName()+" 导入失败：");
					List<String> messageList = BeanValidators.extractPropertyAndMessageAsList(ex, ": ");
					for (String message : messageList){
						failureMsg.append(message+"; ");
						failureNum++;
					}
				}catch (Exception ex) {
					failureMsg.append("<br/>学号 "+student.getStudentNumber()+"<br/>姓名"+student.getStudentName()+" 导入失败："+ex.getMessage());
				}
			}
			if (failureNum>0){
				failureMsg.insert(0, "，失败 "+failureNum+" 条用户，导入信息如下：");
			}
			addMessage(redirectAttributes, "已成功导入 "+successNum+" 条用户"+failureMsg);
		} catch (Exception e) {
			addMessage(redirectAttributes, "导入用户失败！失败信息："+e.getMessage());
		}
		return "redirect:"+adminPath+"/students/dmsStudents/list?repage";

    }
	
	/**
	 * 下载导入学生数据模板
	 * @param response
	 * @param redirectAttributes
	 * @return
	 */
	@RequiresPermissions("students:dmsStudents:view")
    @RequestMapping(value = "template")
    public String importFileTemplate(HttpServletResponse response, RedirectAttributes redirectAttributes) {
		try {
            String fileName = "学生数据导入模板.xlsx";
    		List<DmsStudents> list = Lists.newArrayList(); 
    		new ExportExcel("学生数据", DmsStudents.class, 2).setDataList(list).write(response, fileName).dispose();
    		return null;
		} catch (Exception e) {
			addMessage(redirectAttributes, "导入模板下载失败！失败信息："+e.getMessage());
		}
		return "redirect:"+Global.getAdminPath()+"/students/dmsStudents/list?repage";
    }

	
	
	
	/**
	 * 
	 * query:(学生信息查询)
	 * 
	 * @param dmsStudents
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	
	@RequiresPermissions("students:dmsStudents:view")
	@RequestMapping(value = "query")
	public String query(DmsStudents dmsStudents, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<DmsStudents> page = dmsStudentsService.findPage(new Page<DmsStudents>(request, response), dmsStudents); 
		model.addAttribute("page", page);
		return "hydms/students/dmsStudentsQuery";
	}
	
	
	
	/**
	 * 
	 * list:(信息录入)
	 * 
	 * @param dmsStudents
	 * @param request
	 * @param response
	 * @param model
	 * @return
	 */
	@RequiresPermissions("students:dmsStudents:view")
	@RequestMapping(value = "list")
	public String list(DmsStudents dmsStudents, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<DmsStudents> page = dmsStudentsService.findPages(new Page<DmsStudents>(request, response), dmsStudents); 
		model.addAttribute("page", page);
		return "hydms/students/dmsStudentsList";
	}
    /**
     * 
     * form:(信息录入表单)
     * 
     * @param dmsStudents
     * @param model
     * @return
     */
	@RequiresPermissions("students:dmsStudents:view")
	@RequestMapping(value = "form")
	public String form(DmsStudents dmsStudents, Model model) {
		model.addAttribute("dmsStudents", dmsStudents);
		return "hydms/students/dmsStudentsForm";
	}
    /**
     * 
     * save:(这里用一句话描述这个方法的作用)
     * 
     * @param dmsStudents
     * @param model
     * @param redirectAttributes
     * @return
     */
	@RequiresPermissions("students:dmsStudents:edit")
	@RequestMapping(value = "save")
	public String save(DmsStudents dmsStudents, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, dmsStudents)){
			return form(dmsStudents, model);
		}
		dmsStudentsService.save(dmsStudents);
		addMessage(redirectAttributes, "保存学生信息成功");
		return "redirect:"+Global.getAdminPath()+"/students/dmsStudents/list?repage";
	}
	/**
	 * 
	 * delete:(这里用一句话描述这个方法的作用)
	 * 
	 * @param dmsStudents
	 * @param redirectAttributes
	 * @return
	 */
	@RequiresPermissions("students:dmsStudents:edit")
	@RequestMapping(value = "delete")
	public String delete(DmsStudents dmsStudents, RedirectAttributes redirectAttributes) {
		dmsStudentsService.delete(dmsStudents);
		addMessage(redirectAttributes, "删除学生信息成功");
		return "redirect:"+Global.getAdminPath()+"/students/dmsStudents/list?repage";
	}

}